from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-04-23 14:02:02.043369
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 23, Apr, 2022
Time: 14:02:06
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.0509
Nobs: 635.000 HQIC: -49.4371
Log likelihood: 7754.85 FPE: 2.65048e-22
AIC: -49.6822 Det(Omega_mle): 2.30277e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.328050 0.062464 5.252 0.000
L1.Burgenland 0.104811 0.039565 2.649 0.008
L1.Kärnten -0.110300 0.020734 -5.320 0.000
L1.Niederösterreich 0.195496 0.082707 2.364 0.018
L1.Oberösterreich 0.120135 0.081578 1.473 0.141
L1.Salzburg 0.258806 0.041995 6.163 0.000
L1.Steiermark 0.044299 0.055211 0.802 0.422
L1.Tirol 0.104337 0.044697 2.334 0.020
L1.Vorarlberg -0.063866 0.039459 -1.619 0.106
L1.Wien 0.024355 0.072285 0.337 0.736
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.052362 0.133630 0.392 0.695
L1.Burgenland -0.034863 0.084642 -0.412 0.680
L1.Kärnten 0.041210 0.044357 0.929 0.353
L1.Niederösterreich -0.195915 0.176938 -1.107 0.268
L1.Oberösterreich 0.451542 0.174523 2.587 0.010
L1.Salzburg 0.285333 0.089842 3.176 0.001
L1.Steiermark 0.107355 0.118114 0.909 0.363
L1.Tirol 0.309857 0.095622 3.240 0.001
L1.Vorarlberg 0.024404 0.084416 0.289 0.773
L1.Wien -0.032605 0.154642 -0.211 0.833
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.189688 0.031972 5.933 0.000
L1.Burgenland 0.089636 0.020251 4.426 0.000
L1.Kärnten -0.007665 0.010613 -0.722 0.470
L1.Niederösterreich 0.246408 0.042334 5.821 0.000
L1.Oberösterreich 0.159374 0.041756 3.817 0.000
L1.Salzburg 0.040821 0.021496 1.899 0.058
L1.Steiermark 0.026210 0.028260 0.927 0.354
L1.Tirol 0.085074 0.022878 3.719 0.000
L1.Vorarlberg 0.054678 0.020197 2.707 0.007
L1.Wien 0.117318 0.036999 3.171 0.002
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.110507 0.032054 3.448 0.001
L1.Burgenland 0.043816 0.020303 2.158 0.031
L1.Kärnten -0.013731 0.010640 -1.291 0.197
L1.Niederösterreich 0.176676 0.042442 4.163 0.000
L1.Oberösterreich 0.332028 0.041862 7.931 0.000
L1.Salzburg 0.101782 0.021550 4.723 0.000
L1.Steiermark 0.111606 0.028332 3.939 0.000
L1.Tirol 0.093749 0.022937 4.087 0.000
L1.Vorarlberg 0.060216 0.020249 2.974 0.003
L1.Wien -0.017397 0.037094 -0.469 0.639
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.112570 0.059844 1.881 0.060
L1.Burgenland -0.045076 0.037906 -1.189 0.234
L1.Kärnten -0.045798 0.019865 -2.305 0.021
L1.Niederösterreich 0.140288 0.079239 1.770 0.077
L1.Oberösterreich 0.162345 0.078158 2.077 0.038
L1.Salzburg 0.284153 0.040235 7.062 0.000
L1.Steiermark 0.057246 0.052896 1.082 0.279
L1.Tirol 0.161597 0.042823 3.774 0.000
L1.Vorarlberg 0.097938 0.037805 2.591 0.010
L1.Wien 0.077017 0.069254 1.112 0.266
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.058011 0.047075 1.232 0.218
L1.Burgenland 0.028641 0.029817 0.961 0.337
L1.Kärnten 0.052242 0.015626 3.343 0.001
L1.Niederösterreich 0.202030 0.062331 3.241 0.001
L1.Oberösterreich 0.328669 0.061480 5.346 0.000
L1.Salzburg 0.038307 0.031649 1.210 0.226
L1.Steiermark 0.007861 0.041609 0.189 0.850
L1.Tirol 0.125516 0.033685 3.726 0.000
L1.Vorarlberg 0.065215 0.029738 2.193 0.028
L1.Wien 0.094365 0.054477 1.732 0.083
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.170201 0.056403 3.018 0.003
L1.Burgenland 0.006042 0.035726 0.169 0.866
L1.Kärnten -0.065502 0.018723 -3.499 0.000
L1.Niederösterreich -0.099213 0.074683 -1.328 0.184
L1.Oberösterreich 0.206617 0.073663 2.805 0.005
L1.Salzburg 0.055669 0.037921 1.468 0.142
L1.Steiermark 0.240583 0.049854 4.826 0.000
L1.Tirol 0.501436 0.040361 12.424 0.000
L1.Vorarlberg 0.063437 0.035631 1.780 0.075
L1.Wien -0.076818 0.065272 -1.177 0.239
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.148534 0.062525 2.376 0.018
L1.Burgenland 0.000958 0.039604 0.024 0.981
L1.Kärnten 0.061648 0.020755 2.970 0.003
L1.Niederösterreich 0.175372 0.082788 2.118 0.034
L1.Oberösterreich -0.055833 0.081658 -0.684 0.494
L1.Salzburg 0.208568 0.042037 4.962 0.000
L1.Steiermark 0.137542 0.055265 2.489 0.013
L1.Tirol 0.061538 0.044741 1.375 0.169
L1.Vorarlberg 0.146729 0.039498 3.715 0.000
L1.Wien 0.117193 0.072356 1.620 0.105
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.377084 0.036905 10.218 0.000
L1.Burgenland -0.002071 0.023376 -0.089 0.929
L1.Kärnten -0.021316 0.012250 -1.740 0.082
L1.Niederösterreich 0.208732 0.048865 4.272 0.000
L1.Oberösterreich 0.229098 0.048198 4.753 0.000
L1.Salzburg 0.038696 0.024812 1.560 0.119
L1.Steiermark -0.012500 0.032620 -0.383 0.702
L1.Tirol 0.091620 0.026408 3.469 0.001
L1.Vorarlberg 0.052824 0.023313 2.266 0.023
L1.Wien 0.040062 0.042708 0.938 0.348
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.035719 0.111922 0.173186 0.140102 0.101372 0.082273 0.036152 0.209632
Kärnten 0.035719 1.000000 -0.022987 0.133047 0.051525 0.088518 0.443131 -0.063866 0.091015
Niederösterreich 0.111922 -0.022987 1.000000 0.321064 0.127491 0.281618 0.072119 0.158525 0.295368
Oberösterreich 0.173186 0.133047 0.321064 1.000000 0.218677 0.305476 0.169158 0.143582 0.244974
Salzburg 0.140102 0.051525 0.127491 0.218677 1.000000 0.128854 0.095588 0.108658 0.127381
Steiermark 0.101372 0.088518 0.281618 0.305476 0.128854 1.000000 0.138985 0.115674 0.044378
Tirol 0.082273 0.443131 0.072119 0.169158 0.095588 0.138985 1.000000 0.067284 0.150476
Vorarlberg 0.036152 -0.063866 0.158525 0.143582 0.108658 0.115674 0.067284 1.000000 0.000925
Wien 0.209632 0.091015 0.295368 0.244974 0.127381 0.044378 0.150476 0.000925 1.000000